const http = require("http");
const logger = require("../_unit/logs");

const server = http.createServer((request, response) => {
  let urlObj = new URL(request.url, "http://127.0.0.1:3000/");
  let pathname = urlObj.pathname;
  let mathpage = MathPage(pathname);

  response.setHeader("Content-Type", "text/html; charset=utf-8");
  response.end(mathpage);
});

server.listen(3000, () => {
  console.log("开启3000服务!");
});

function MathPage(pathname) {
  let strHtml = ``;
  switch (pathname) {
    case "/login":
      strHtml = `<h2>登录页面</h2>`;
      break;

    case "/reg":
      strHtml = `<h2>注册页面</h2>`;
      break;

    default:
      strHtml = `<h2>40未找到页面</h2>`;
      break;
  }

  return strHtml;
}
